package uk.org.aspellclark.gedcom.model.records;

import java.util.ArrayList;
import java.util.List;

import uk.org.aspellclark.gedcom.model.ChangeDate;
import uk.org.aspellclark.gedcom.model.FamilyEventType;
import uk.org.aspellclark.gedcom.model.LdsSpouseSealing;
import uk.org.aspellclark.gedcom.model.UserReference;
import uk.org.aspellclark.gedcom.model.structures.FamilyEventStructure;
import uk.org.aspellclark.gedcom.model.structures.MultimediaLink;
import uk.org.aspellclark.gedcom.model.structures.NoteStructure;
import uk.org.aspellclark.gedcom.model.structures.SourceCitation;

/**
<pre>FAM_RECORD:=
    n @&lt;XREF:FAM>@ FAM            {1:1}
        +1 RESN &lt;RESTRICTION_NOTICE>   {0:1)
        +1 &lt;&lt;FAMILY_EVENT_STRUCTURE>>     {0:M}
        +1 HUSB @&lt;XREF:INDI>@             {0:1}
        +1 WIFE @&lt;XREF:INDI>@             {0:1}
        +1 CHIL @&lt;XREF:INDI>@             {0:M}
        +1 NCHI &lt;COUNT_OF_CHILDREN>       {0:1}
        +1 SUBM @&lt;XREF:SUBM>@             {0:M}
        +1 &lt;&lt;LDS_SPOUSE_SEALING>>         {0:M} p.36
        +1 REFN &lt;USER_REFERENCE_NUMBER>   {0:M}
            +2 TYPE &lt;USER_REFERENCE_TYPE> {0:1}
        +1 RIN &lt;AUTOMATED_RECORD_ID>      {0:1}
        +1 &lt;&lt;CHANGE_DATE>>                {0:1}
        +1 &lt;&lt;NOTE_STRUCTURE>>             {0:M}
        +1 &lt;&lt;SOURCE_CITATION>>            {0:M}
        +1 &lt;&lt;MULTIMEDIA_LINK>>            {0:M}</pre>
The FAMily record is used to record marriages, common law marriages, and family unions caused by
two people becoming the parents of a child. There can be no more than one HUSB/father and one
WIFE/mother listed in each FAM_RECORD. If, for example, a man participated in more than one
family union, then he would appear in more than one FAM_RECORD. The family record structure
assumes that the HUSB/father is male and WIFE/mother is female.<br/>
The preferred order of the CHILdren pointers within a FAMily structure is chronological by birth.
 */
public class FamRecord extends GedcomRecord {

	public String restrictionNotice;
	public List<FamilyEventStructure> events = new ArrayList<FamilyEventStructure>();
	public String husb;
	public String wife;
	public List<String> childrenXRef = new ArrayList<String>();
	public int nbrChildren;
	public List<String> submXRef;
	public List<LdsSpouseSealing> ldsSpouseSealing;
	public List<UserReference> refn;
	public String rin;
	public ChangeDate changeDate;
	public List<NoteStructure> note;
	public List<SourceCitation> sourceCitation;
	public List<MultimediaLink> multimediaLink;

	/**
	 * @param idFromString
	 */
	public FamRecord(String idFromString) {
		this.xref = idFromString;
	}

	public CharSequence getDivorceDate() {
		String dobStr = "";
		for (FamilyEventStructure ie : this.events) {
			if (ie.type != null && ie.type.equalsIgnoreCase(FamilyEventType.DIVORCE.tag)) {
				if (ie.detail.eventDetail.date != null) {
					dobStr = ie.detail.eventDetail.date;
				}
			}
		}
		return dobStr;
	}

	public CharSequence getMarriageDate() {
		String dobStr = "";
		for (FamilyEventStructure ie : this.events) {
			if (ie.type != null && ie.type.equalsIgnoreCase(FamilyEventType.MARRIAGE.tag)) {
				if (ie.detail.eventDetail.date != null) {
					dobStr = ie.detail.eventDetail.date;
				}
			}
		}
		return dobStr;
	}

}
